package com.quanyan.operative.web;

import com.quanyan.api.APIResponse;
import com.quanyan.operative.model.req.ReqBlessingUser;
import com.quanyan.operative.model.resp.RespBlessingUser;
import com.quanyan.operative.service.BlessingService;
import com.quanyan.operative.service.TbUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by zhang on 16/11/5.
 */
@RestController
@RequestMapping(value = "/api/operative/blessing")
public class BlessingController {
    @Autowired
    private BlessingService blessingService;

    @Autowired
    private TbUserInfoService tbUserInfoService;


    @RequestMapping(value = "get")
    public APIResponse<List<RespBlessingUser>> get(@RequestBody ReqBlessingUser reqBlessingUser){
        List<RespBlessingUser> respBlessingUserList = blessingService.getUserBlessingList(reqBlessingUser);
        return APIResponse.returnSuccess(respBlessingUserList);
    }


    @RequestMapping(value = "updateSetting" ,method = RequestMethod.POST)
    public APIResponse updateSetting(@RequestBody Map map){
      Integer pageIndex =  map.get("pageIndex") == null ? 1 :Integer.parseInt(map.get("pageIndex").toString());
      Integer pageSize =  map.get("pageSize") == null ? 5000 :Integer.parseInt(map.get("pageSize").toString());
      return tbUserInfoService.updateUserSetting(pageIndex,pageSize);
    }
}
